package logical;
import java.util.Vector;


public class SetState {
	private Vector<State> set; 
	private boolean isFinal;
	private Vector<TransitionDFA> transitions;
	public boolean visited;
	public int vertexNo;
	public SetState(Vector<State> set){
		this.set = set;
		isFinal=false;
		visited=false;
		vertexNo=-1;
		transitions = new Vector<TransitionDFA>();
		for(int i =0; i<set.size();i++)
		{
			if(set.get(i).equals(DFA.automataFinalState))
			{
				isFinal=true;
				break;
			}
		}
	}
	public Vector<String> listTransitions()
	{
		Vector<String> transitions = new Vector<String>();
		for(int i =0; i<set.size();i++)
		{
			for(int j = 0; j<set.get(i).getTransitions().size(); j++)
			{
				String trans = set.get(i).getTransitions().get(j).getValue();
				if(!transitions.contains(trans) && !trans.equals(Transition.EPSILON.toString()))
					transitions.add(trans);
			}
		}
		return transitions;
	}

	public Vector<State> setStateReachable(String transition )
	{
		Vector<State> new_set = new Vector<State>();
		for(int i = 0; i< this.set.size();i++)
		{
			for(int j= 0 ; j<this.set.get(i).getTransitions().size();j++)
			{
				if(this.set.get(i).getTransitions().get(j).getValue().equals(transition))
				{
					State final_tmp = this.set.get(i).getTransitions().get(j).getDestinationState();
					Vector<State> set_tmp = new Vector<State>();
					new_set.addAll(final_tmp.statesReachable(set_tmp));
					
				}
			}
		}
		return new_set;
	}
	public boolean isFinal() {
		return isFinal;
	}
	public void setFinal(boolean isFinal) {
		this.isFinal = isFinal;
	}
	public Vector<TransitionDFA> getTransitions() {
		return transitions;
	}
	public void setTransitions(Vector<TransitionDFA> transitions) {
		this.transitions = transitions;
	}
	public boolean equals(Object setstate)
	{
		if(this.set.size() != ((SetState) setstate).getSet().size())
			return false;
		for(int i =0; i<((SetState) setstate).getSet().size();i++)
		{
			if(!this.set.contains(((SetState) setstate).getSet().get(i)))
					return false;
		}
		return true;
	}
	public Vector<State> getSet() {
		return set;
	}
}
